<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script type="text/javascript">
  let a=0
  
  window.onblur = () => {
    console.log("页面切屏"+a++)
  } 
  window.addEventListener("beforeunload", (event) => { 
     a=Number(localStorage.getItem("a"))+1
     localStorage.setItem("a","页面关闭刷新事件"+a)
  });
  console.log(localStorage.getItem("a"))
</script>
</html>